﻿@using Presentation.Web.Admin
@model Application.Admin.Dto.AutoPushDto
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Ajax.BeginForm("addautopush", "push", new AjaxOptions
{
    HttpMethod = "Post",
    OnBegin = "checkedAddForm",
    OnFailure = "addFailure",
    OnSuccess = "addSuccess"
}))
{
    @Html.ValidationSummary(true)
    <fieldset class="module width_full">
        @Html.Partial("_AutoPushForm")
    </fieldset>
    <p>
        @{
    if (Html.HasUiPermission(this.ViewContext, "addautopush"))
    {
            <input type="submit" value="添加" class="alt_btn module_margin" />
    }  
        }
    </p>
}
<script type="text/javascript">

    function checkedAddForm() {
        var res = true;
        if ($('#Name').val() == "") {
            $('#Name').focus();
            alert("请输入定时推送名");
            res = false;
            return res;
        }
        if ($('#Content').val() == "") {
            alert("定时推送不能为空");
            $('#Content').focus();
            res = false;
            return res;
        }
        if ($('#IntervalTime').val() == "") {
            alert("推送时间间隔不能为空");
            $('#IntervalTime').focus();
            res = false;
            return res;
        }
        else {
            var interval = $('#Interval').val();
            if (interval <= 0) {
                if (confirm('当前这样的设置，推送只会在开始时间点生效')) {
                    res = true;
                    return true;
                }
                else {
                    res = false;
                    return res;
                }
            }
        }
        if ($('#ExpiredDateTime').val() == "") {
            alert("过期时间不能为空");
            $('#ExpiredDateTime').focus();
            res = false;
            return res;
        }
        return res;
    }

    function addSuccess(res) {
        if (res.success) {
            alert("添加成功");
            window.location.reload();
        }
        else {
            alert(res.message);
        }
    }

    function addFailure() {
        alert("添加失败了T_T！");
    }
</script>
